/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-09 09:49:40
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-24 15:49:18
 * @FilePath: \linePatrol\vue-element-plus-admin\src\store\modules\plangroup.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { store } from '../index'
import { MeterLedger, ProducerLedger, UserLedgerListType } from '@/api/securcheck/type'
import SecurCheckProducerLedgerApi from '@/api/securcheck/ProducerLedger'
import { ScheduleSendTaskDetailType } from '@/api/linePatrol/type'
import SetSecurCheckApi from '@/api/securcheck/SetSecurCheck'
export interface StateUserType {
  Selected: UserLedgerListType[]
  NotSelect: UserLedgerListType[]
}
export const useSecurCheckStore = defineStore('securcheck', {
  state: () => {
    return {
      MeterLedgers: {} as unknown as MeterLedger,
      AllProducerLedger: [] as unknown as ProducerLedger[],
      UserGroupId: 0 as number | undefined,
      UniteGroupId: 0 as number | undefined,
      nowSelectRightData: [] as UserLedgerListType[],
      groupUserCom: 0 as number | undefined, //0-用户 ，1 -单位
      ScheduleSecurTaskDetail: {} as ScheduleSendTaskDetailType,
      activeName: '0' as string | undefined,
      SecurTaskID: '' as string | undefined
    }
  },
  getters: {
    getMeterLedger(): MeterLedger {
      return this.MeterLedgers
    },
    getAllProducerLedger(): ProducerLedger[] {
      return this.AllProducerLedger
    },
    getUserGroupId(): number | undefined {
      return this.UserGroupId
    },
    getUniteGroupId(): number | undefined {
      return this.UniteGroupId
    },
    getnowSelectRightData(): UserLedgerListType[] {
      return this.nowSelectRightData
    },
    getgroupUserCom(): number | undefined {
      return this.groupUserCom
    },
    getScheduleSecurTaskDetail(): ScheduleSendTaskDetailType {
      return this.ScheduleSecurTaskDetail
    }
  },
  actions: {
    async setMeterLedger(data: MeterLedger) {
      if (data.tbUserLedger) {
        data['userNumebr'] = data?.tbUserLedger.userNumebr
        data['userName'] = data.tbUserLedger.userName
        data['userPhone'] = data.tbUserLedger.userPhone
        data['gogasAddre'] = data.tbUserLedger.gogasAddre
        data['floorNo'] = data.tbUserLedger.floorNo
        data['unitNo'] = data.tbUserLedger.unitNo
        data['roomNo'] = data.tbUserLedger.roomNo
        data['community'] = data.tbUserLedger.community
      }
      this.MeterLedgers = data
    },
    async setAllProducerLedger() {
      const res = await SecurCheckProducerLedgerApi.GetAllProducerLedger()
      this.AllProducerLedger = res
    },
    setUserGroupId(id: number | undefined) {
      this.UserGroupId = id
    },
    setUniteGroupId(id: number | undefined) {
      this.UniteGroupId = id
    },
    setgroupUserCom(data: number | undefined) {
      this.groupUserCom = data
    },
    async setScheduleSecurTaskDetail(uuid: string | undefined) {
      this.ScheduleSecurTaskDetail = await SetSecurCheckApi.GetScheduleSecurTask(uuid)
      if (this.ScheduleSecurTaskDetail) {
        this.activeName = this.ScheduleSecurTaskDetail.planType
      }
    },
    setSecurTaskID(id: string | undefined) {
      this.SecurTaskID = id
    }
  },
  persist: true
})

export const useLockStoreWithOut = () => {
  return useSecurCheckStore(store)
}
